package com.ruoyi.project.gxgw_modules.pet.controller;

import java.util.List;

import com.ruoyi.project.gxgw_modules.pet.domain.Pet;
import com.ruoyi.project.gxgw_modules.pet.service.IPetService;
import com.ruoyi.project.gxgw_modules.pet.vo.PetVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 宠物 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-18
 */
@Controller
@RequestMapping("/gxgw_modules/pet")
public class PetController extends BaseController
{
    private String prefix = "gxgw_modules/pet";
	
	@Autowired
	private IPetService petService;
	
	@RequiresPermissions("system:pet:view")
	@GetMapping()
	public String pet()
	{
	    return prefix + "/pet";
	}
	
	/**
	 * 查询宠物列表
	 */
	@RequiresPermissions("system:pet:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PetVO pet)
	{
		startPage();
        List<PetVO> list = petService.selectPetList(pet);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出宠物列表
	 */
	@RequiresPermissions("system:pet:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PetVO pet)
    {
    	List<PetVO> list = petService.selectPetList(pet);
        ExcelUtil<PetVO> util = new ExcelUtil<PetVO>(PetVO.class);
        return util.exportExcel(list, "pet");
    }
	
	/**
	 * 新增宠物
	 */
//	@GetMapping("/add")
//	public String add()
//	{
//	    return prefix + "/add";
//	}
	
	/**
	 * 新增保存宠物
	 */
//	@RequiresPermissions("system:pet:add")
//	@Log(title = "宠物", businessType = BusinessType.INSERT)
//	@PostMapping("/add")
//	@ResponseBody
//	public AjaxResult addSave(Pet pet)
//	{
//		return toAjax(petService.insertPet(pet));
//	}

	/**
	 * 修改宠物
	 */
	@GetMapping("/edit/{petId}")
	public String edit(@PathVariable("petId") Integer petId, ModelMap mmap)
	{
		Pet pet = petService.selectPetById(petId);
		mmap.put("pet", pet);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存宠物
	 */
	@RequiresPermissions("system:pet:edit")
	@Log(title = "宠物", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Pet pet)
	{
		return toAjax(petService.updatePet(pet));
	}
	
	/**
	 * 删除宠物
	 */
	@RequiresPermissions("system:pet:remove")
	@Log(title = "宠物", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		return toAjax(petService.deletePetByIds(ids));
	}
	
}
